﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ExtBusiness;
using ExtBusiness.Admin;
using WF_Business;
using ExtBusiness.FlowOperation;

public partial class Xnjc_staff_assess : PageBase
{
    public System.String displayType = string.Empty;
    public System.String wname = string.Empty;
    public System.String stepName = string.Empty;
    public System.String userID = string.Empty;
    public System.String intervalType = string.Empty;

    public System.String timeFromOfAccept = string.Empty;
    public System.String timeToOfAccept = string.Empty;

    public DataTable list = null;
    public DataTable relatedUsers = null;
    public String sql = "";
    public DataTable allWorkFlowNames;
    public double secondsPerDay;
    protected string strhtml = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
         displayType = Request["displayType"];
         wname = Request["wname"];
         stepName = Request["stepName"];
        userID = Request["userID"];
         intervalType = Request["intervalType"];

         timeFromOfAccept = Request["timeFromOfAccept"];
        timeToOfAccept = Request["timeToOfAccept"];


        if (!String.IsNullOrEmpty(wname) && !String.IsNullOrEmpty(stepName))
        {
            sql = string.Format(@"SELECT * FROM ST_USER_GROUP WHERE GID in (select gid from 
            st_group_in_step where wid in (SELECT Wid FROM ST_WORKFLOW WHERE WName='{0}' 
            AND rot=0) and stpname='{1}')", wname, stepName);
            SysParams.OAConnection().RunSql(sql, out relatedUsers);
        }

        if (!String.IsNullOrEmpty(wname) && !String.IsNullOrEmpty(stepName) && !String.IsNullOrEmpty(userID))
        {
            ClsWorkFlow work = new ClsWorkFlow();
            list = work.statisticStepOfStaff(wname, stepName, userID, timeFromOfAccept, timeToOfAccept, intervalType);
        }

        sql = "select wname from st_workflow group by wname";

        SysParams.OAConnection().RunSql(sql, out allWorkFlowNames);

         secondsPerDay = SystemConfig.SecondInEveryDay;

         if (!"charts".Equals(displayType)) 
         {
             if (list != null)
                for (int i = 0; i < list.Rows.Count; i++)
                {
                    DataRow m = (DataRow)list.Rows[i];
                    sql = m["detailSql"].ToString();
                   strhtml+="  <tr><td>"+m["YEAR"].ToString()+"年";
                                              if (!String.IsNullOrEmpty(m["MONTH"].ToString()))
                                              {
                strhtml+=m["MONTH"].ToString()+"月";
                                                 if (!String.IsNullOrEmpty(m["DAY"].ToString()))
                                                 {
                strhtml+=m["DAY"].ToString()+"日";
                                               }
                                              }
                strhtml+="</td><td>"+m["CNT"].ToString()+"</td><td>";

                    System.String totalTimeStr = m["TOTAL_TIME"].ToString();
                    long totalTime = 0;
                    if (!string.IsNullOrEmpty(totalTimeStr))
                    {
                        totalTime = System.Int64.Parse(totalTimeStr);
                    }
                    System.String cntStr = m["CNT"].ToString();
                    int cnt = System.Int32.Parse(cntStr);

                    if (cnt != 0)
                    {
                        strhtml += "" + ClsWorkDaySet.ToDefaultTime(totalTime / cnt);
                    }

                    sql = Server.UrlEncode(sql);
                    strhtml += "</td><td><a href='../QueryAndCollect/TaskQueryInstance.aspx?sql=" + sql + ">详细</a></td></tr>";
            }
         }
    }
}
